/**
	Name    : kyo-validate
	Author  : Kyousuke_W
	Email   : 609671961@qq.com
	Version : 1.0.0
**/
$.fn.extend({
	kyoValidate : function(){
		this.each(function(){
			var formObj = $(this);
			var inputObj = $(':input', formObj);
        	inputObj.filter('.kyoVal').focus(function(){
        		var item = $(this);
                var defaultValue = item.attr('data-original-title');
                if(defaultValue && defaultValue == item.val()){
                    item.val('');
                }
        	}).blur(function(){
        		var item = $(this);
                var defaultValue = item.attr('data-original-title');
                if(defaultValue && item.val() == ''){
                    item.attr('data-original-title',defaultValue);
                }
        	    _hasMethod($(this), this.form);
        	})
        });
        this.submit(function(){
            return _validate(this);
        });
    }
})
function _validate(form){
    var success = true;
    $(':input', form).each(function(){
        var o = $(this);
        if(settings.validationGroup){
            if(settings.validationGroup != o.attr('jvgroup')) return;
        }
        if(!_isCorrect(o, form)){
            success = false;
            if(!settings.isbubble)return false;
        }
    });
    if(success && settings.oncompleted)success = settings.oncompleted(form);
                    return success;
                }
}
//input validate method
function _hasMethod(item, form){
	var method = item.attr('kyomethod');
	if(method){
		f = window[method](item);
		if(f){
            item.parent('.form-group').removeClass('has-error');
            item.tooltip('destroy');
		}else{
            item.parent('.form-group').addClass('has-error');            
            item.tooltip('show');
		}
	}
}